package com.oh.iris.runner;

import com.oh.core.server.OhSocketServer;
import com.oh.core.server.WebSocketNettyServer;
import com.oh.iris.server.handler.HeartBeatServer;
import com.oh.iris.server.handler.TestLastHandler;
import io.netty.channel.ChannelHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听Spring容器启动完成，完成后启动Netty服务器
 */
@Component
public class NettyStartListener implements ApplicationRunner {

    @Resource
    OhSocketServer ohSocketServer;

    @Autowired
    TestLastHandler testLastHandler;

    @Autowired
    HeartBeatServer heartBeatServer;

    @Resource
    private WebSocketNettyServer webSocketNettyServer;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 字节
//        socketServer.start();
        // 消息实体
        ChannelHandler[] lastHandlers = new ChannelHandler[2];
        lastHandlers[0] = testLastHandler;
        lastHandlers[1] = heartBeatServer;
        ohSocketServer.start(lastHandlers);
        // webSocket服务
        webSocketNettyServer.start();
    }
}
